home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group98c.txt / 000077_icon-group-sender _Fri Nov 13 16:45:35 1998.msg < prev    next >
Internet Message Format  |  2000-09-20  |  4KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) with SMTP id QAA04592
  4.     for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Fri, 13 Nov 1998 16:45:31 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA07516; Fri, 13 Nov 1998 16:45:30 -0700
  7. Message-Id: <4FD6422BE942D111908D00805F3158DF0757B73A@RED-MSG-52>
  8. From: Todd Proebsting <toddpro@microsoft.com>
  9. To: "'Mark Laster'" <mlaster@smart.net>, icon-group@optima.CS.Arizona.EDU
  10. Subject: RE: Coding multi-part patterns, as in SNOBOL
  11. Date: Fri, 13 Nov 1998 12:59:48 -0800
  12. X-Mailer: Internet Mail Service (5.5.2232.9)
  13. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  14. Status: RO
  15.  
  16. I believe the following "strip()" routine will do what you want.  (It is
  17. possible to write it more concisely, but at the expense of clarity.)  The
  18. "main()" routine simply provides a driver routine that reads lines, strips
  19. them and prints the results.
  20.  
  21. Todd Proebsting
  22.  
  23. procedure main()
  24.     while write(strip(read()))
  25. end
  26.  
  27. procedure strip(s)
  28.     s ? {                            # scan
  29. string
  30.         tab(many(' '))                # tab past spaces
  31.         if tab(many('>')) then {        # tab past >'s
  32.             return tab(0)            # return remainder
  33.         } else {
  34.             return s            # no >'s, so return
  35. s
  36.         }
  37.     }
  38. end
  39.  
  40.  
  41. -----Original Message-----
  42. From: Mark Laster [mailto:mlaster@smart.net]
  43. Sent: Friday, November 13, 1998 9:09 AM
  44. To: icon-group@optima.CS.Arizona.EDU
  45. Subject: Coding multi-part patterns, as in SNOBOL
  46.  
  47.  
  48. Subject: Coding multi-part patterns, as in SNOBOL
  49.  
  50. Friday, 11/13/98
  51.  
  52. Hello,
  53.  
  54. After years of programming in SNOBOL, I've been learning ICON, 
  55. but some operations in ICON require me (because I don't know a 
  56. neater way) to write far more lines of code than would be 
  57. necessary in SNOBOL.
  58.  
  59. One of my programs in ICON processes e-mail messages.  It does 
  60. more than the snippet shown here, but for purposes of 
  61. discussion, it removes the "e-mail quotation" marks from lines of 
  62. text.  As you know, those marks in aggregate may be either: 
  63.  
  64.   (1) one or more angle brackets, starting at the left margin, or
  65.  
  66.   (2) one or more spaces, starting at the left margin, FOLLOWED 
  67.       IMMEDIATELY BY one or more angle brackets.
  68.  
  69. To remove these "e-mail quote" marks, I needed about 20 lines, 
  70. as shown below.
  71.  
  72. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  73.  
  74. procedure main ( )
  75.   ...
  76.     # have gotten a line of text, called "rec" here, by now
  77.     repeat {
  78.       if /rec then {
  79.         rec := " "
  80.         break 
  81.         }
  82.  
  83.       else 
  84.       if locnb := many('>', rec) then 
  85.         rec := rec[locnb:0]
  86.  
  87.       if dbg1 := (many(' ', rec)) then {
  88.         if dbg2 := (many('>', rec[dbg1])) then 
  89.           rec := rec[dbg1+dbg2-1:0]
  90.  
  91.         else  # found starting blanks but no ">" immediately after
  92.           break
  93.  
  94.         } # end of "if dbg1 := (many(' ' ..."
  95.  
  96.       else  # rec line does not start with blank or ">"
  97.         break
  98.  
  99.       } # repeat for each workline
  100.       # write the record out
  101.   ...
  102. end
  103.  
  104. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  105.  
  106. To perform the same operation in SNOBOL requires two lines (if 
  107. that many):
  108.  
  109. ...
  110.         qupat = pos(0) (span(" ") | null) span(">") rem . rec
  111. ...
  112. strip   rec qupat :s(strip)
  113. ...
  114. end
  115.  
  116. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  117.  
  118. I've read through the file PATTERNS.ICN, written in 1988, and I
  119. know how to $include it, but I don't know how to use it.  I'd 
  120. be glad to lose some run-time efficiency in order to gain some 
  121. coding-time efficiency.
  122.  
  123. Assuming that there is a way to code the quote-stripping 
  124. operation in ICON more efficiently than I have, optionally 
  125. using the PATTERNS.ICN file or superseding files, could you 
  126. show me how to do it in ICON, so I can see how to combine 
  127. multiple conditions in a match:
  128.  
  129.   (1) starting at the left margin
  130.   (2) optionally encountering one or more blanks
  131.   (3) encountering one or more ">" directly afterward.
  132.  
  133. That would help me learn how to code a variety of complex 
  134. conditions.
  135.  
  136. Thank you very much.
  137.  
  138. Sincerely yours,
  139.  
  140. Mark Laster            (301) 805-4462       mlaster@smart.net
  141. 15775 Easthaven Court
  142. Bowie, MD  20716-2620
  143.  
  144.  
  145.  
  146.